/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "sle_host_service.h"
#include "sle_adapter_manager.h"
#include "sle_flow_monitor_manager.h"
#include "cmd_input.h"
#include <vector>
#include <memory>
#include <cstring>
#include <iterator>

namespace OHOS {
namespace NearLink {
namespace SleStandard {
namespace {
using namespace testing::ext;
SleAdapterManager *adapterManager_ = nullptr;
SleHostService *hostService_ = nullptr;
SleFlowMonitorManager *monitorManager_ = nullptr;
} // namespace

class HostHandlerTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

void HostHandlerTest::SetUpTestCase() {}

void HostHandlerTest::TearDownTestCase() {}

void HostHandlerTest::SetUp() {
    hostService_ = SleHostService::GetInstance();
    monitorManager_ = SleFlowMonitorManager::GetInstance();
    adapterManager_ = SleAdapterManager::GetInstance();
}

void HostHandlerTest::TearDown() {}

// HWTEST_F(HostHandlerTest, SleEnableTest, TestSize.Level1)
// {
//     SleErrorCode ret = hostService_->EnableSle();
//     EXPECT_EQ(ret, 0);
// }

HWTEST_F(HostHandlerTest, SleDisableTest, TestSize.Level1)
{
    SleErrorCode ret = hostService_->DisableSle();
    EXPECT_EQ(ret, SLE_ERR_SLE_ERROR);
}

HWTEST_F(HostHandlerTest, GetSleStateTest, TestSize.Level1)
{
    int32_t state;
    SleErrorCode ret = adapterManager_->GetState(state);
    EXPECT_EQ(ret, 0);
}

// HWTEST_F(HostHandlerTest, SetHostAddressTest, TestSize.Level1)
// {
//     SleDeviceAddress hostAddr = {
//         .addrType = SLE_PUBLIC_ADDRESS_TYPE,
//     };
//     char addr[18];
//     strcpy(addr, "00:11:aa:bb:f1:6b");
//     Str2Mac(hostAddr.addr, addr);
//     SleAddress address(hostAddr);
//     SleErrorCode ret = hostService_->SetHostAddress(address);
//     EXPECT_EQ(ret, 0);
// }

HWTEST_F(HostHandlerTest, GetHostAddressTest, TestSize.Level1)
{
    SleDeviceAddress addrStu = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    SleAddress address(addrStu);
    GTEST_LOG_(INFO)    << "------- GetHostAddress start ---------";
    SleErrorCode ret = hostService_->GetHostAddress(address);
    GTEST_LOG_(INFO)    << "------- GetHostAddress end ---------";
    EXPECT_EQ(ret, SLE_ERR_SLE_ERROR);
}

HWTEST_F(HostHandlerTest, SetHostNameTest, TestSize.Level1)
{
    std::string name = "";
    SleErrorCode ret = hostService_->SetHostName(name);
    EXPECT_EQ(ret, SLE_ERR_INVALID_PARAM);
}

HWTEST_F(HostHandlerTest, GetHostNameTest, TestSize.Level1)
{
    std::string name = "";
    SleErrorCode ret = hostService_->GetHostName(name);
    EXPECT_EQ(ret, SLE_ERR_SLE_ERROR);
}

HWTEST_F(HostHandlerTest, StartFlowMonitor, TestSize.Level1)
{
    SleErrorCode ret = monitorManager_->StartFlowMonitor();
    EXPECT_EQ(ret, 0);
}

HWTEST_F(HostHandlerTest, StopFlowMonitorTest, TestSize.Level1)
{
    SleErrorCode ret = monitorManager_->StopFlowMonitor();
    EXPECT_EQ(ret, 0);
}
}
} // namespace NetManagerStandard
} // namespace OHOS
